/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bizfty.apiexecutor;

import com.bizfty.api.apiexecutor.gateways.ApiExe;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import java.io.IOException;
import java.util.Arrays;
import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 * @author johns
 */
@Configuration
public class CxfConfig {

    @Autowired
    private Bus bus;

    @Bean
    @Qualifier("apiExe")
    public Endpoint apiExeEndpoint(ApiExe apiExe) throws IOException {
        EndpointImpl endpoint = new EndpointImpl(bus, apiExe);
        endpoint.publish("/ApiExeService");
        return endpoint;
    }

    @Bean
    @Qualifier("apiExe")
    public Server apiExeServer(ApiExe apiExe) throws IOException {
        JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
        endpoint.setBus(bus);
        endpoint.setAddress("/ApiExeResource");
        endpoint.setProvider(new JacksonJsonProvider());
        endpoint.setServiceBeans(Arrays.<Object>asList(apiExe));
        return endpoint.create();
    }

}
